package demoMod.invincibleOne.cards.invincible;

import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import com.megacrit.cardcrawl.rooms.MonsterRoom;
import com.megacrit.cardcrawl.rooms.RestRoom;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.interfaces.EnterRoomHook;
import demoMod.invincibleOne.interfaces.SpawnMonsterHook;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;
import demoMod.invincibleOne.relics.TaskGoal;

public class GetBurned extends AbstractInvincibleCard implements EnterRoomHook, SpawnMonsterHook {
    public static final String ID = InvincibleOneMod.makeID("GetBurned");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/GetBurned.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = -2;

    public GetBurned() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.modifier = new ExhaustAtStartOfCombatMod();
        CardModifierManager.addModifier(this, modifier);
        this.tags.add(CardTagsEnum.ALERT);
        this.baseMagicNumber = this.magicNumber = 0;
        this.baseM2 = this.m2 = 5;
        InvincibleOneMod.addToBot(new AbstractGameAction() {
            @Override
            public void update() {
                GetBurned.this.baseMagicNumber = GetBurned.this.magicNumber = GetBurned.this.misc;
                isDone = true;
            }
        });
    }

    @Override
    public boolean onBattleStart() {
        TaskGoal.AddToAlertQueue(34, () -> {
            for (AbstractMonster m : AbstractDungeon.getMonsters().monsters) {
                addToTop(new AbstractGameAction() {
                    @Override
                    public void update() {
                        m.increaseMaxHp(magicNumber, true);
                        isDone = true;
                    }
                });
            }
        });
        return true;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            this.baseM2 += 3;
            this.m2 = this.baseM2;
        };
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }

    @Override
    public void onEnterRoom(AbstractRoom room) {
        if (room instanceof RestRoom) {
            this.misc += this.m2;
            this.baseMagicNumber = this.magicNumber = this.misc;
        }
    }

    @Override
    public void onSpawnMonster(AbstractMonster m) {
        TaskGoal.AddToAlertQueue(34, new TaskGoal.AlertLambda() {
            @Override
            public void run() {
                addToTop(new AbstractGameAction() {
                    @Override
                    public void update() {
                        m.increaseMaxHp(magicNumber, true);
                        isDone = true;
                    }
                });
            }
        });
    }
}